﻿using System;
using System.Collections.Generic;
using System.Text;
using UInt8 = System.Byte;

namespace Ndo.Maths
{
    public class UInteger8 : Integer<UInteger8>
    {
        public UInteger8()
            : this(1)
        { }
        [Ndo.Text.ParsingPattern(@"(\+|-)?\d+")]
        public UInteger8(string text)
            : this(UInt8.Parse(text))
        { }
        public UInteger8(UInt8 i)
        {
            value = i;
        }

        private readonly UInt8 value;
        public static implicit operator UInteger8(UInt8 i)
        {
            return new UInteger8(i);
        }
        public static UInteger8 operator +(UInteger8 i1, UInteger8 i2)
        {
            return new UInteger8((UInt8)(i1.value + i2.value));
        }
        public static UInteger8 operator -(UInteger8 i1, UInteger8 i2)
        {
            return new UInteger8((UInt8)(i1.value - i2.value));
        }
        public static UInteger8 operator *(UInteger8 i1, UInteger8 i2)
        {
            return new UInteger8((UInt8)(i1.value * i2.value));
        }
        public static UInteger8 operator /(UInteger8 i1, UInteger8 i2)
        {
            return new UInteger8((UInt8)(i1.value / i2.value));
        }
        public static UInteger8 operator %(UInteger8 i1, UInteger8 i2)
        {
            return new UInteger8((UInt8)(i1.value % i2.value));
        }
        public static bool operator ==(UInteger8 i1, UInteger8 i2)
        {
            return i1.value == i2.value;
        }
        public static bool operator !=(UInteger8 i1, UInteger8 i2)
        {
            return i1.value != i2.value;
        }

        public override bool Equals(object obj)
        {
            if (obj is UInteger8)
                return this.value == ((UInteger8)obj).value;
            return false;
        }
        public override int GetHashCode()
        {
            return value.GetHashCode();
        }
        public override string ToString()
        {
            return value.ToString();
        }

        public override int CompareTo(UInteger8 other)
        {
            return value.CompareTo(other.value);
        }

        public override SignTypes Sign
        {
            get
            {
                if (value == 0)
                    return SignTypes.Zero;
                return SignTypes.Positive;
            }
        }
    }
}
